package com.hankol.winecellar.adapter

import com.baselibrary.extension.checkNotNull
import com.baselibrary.extension.checkValue
import com.baselibrary.extension.load
import com.baselibrary.utils.CommonUtil
import com.baselibrary.view.RoundCornerImageView
import com.chad.library.adapter.base.BaseQuickAdapter
import com.chad.library.adapter.base.BaseViewHolder
import com.hankol.winecellar.R
import com.hankol.winecellar.bean.LabelConfigFacilityBean
import com.hankol.winecellar.bean.NearbyWineCellarListBean
import com.hankol.winecellar.view.TagCloudView

/*
竖向酒窖列表
* */
class VerticalWinecallarListAdapter : BaseQuickAdapter<NearbyWineCellarListBean, BaseViewHolder>(R.layout.item_vercital_winecaller) {

    private var isStopMarquee = false
    fun setStopMarquee(isStopMarquee: Boolean) {
        this.isStopMarquee = isStopMarquee
        notifyDataSetChanged()
    }

    override fun convert(helper: BaseViewHolder, item: NearbyWineCellarListBean) {
        helper.apply {
            item.let {
                getView<RoundCornerImageView>(R.id.riv_cover).load(mContext, it.wineryImg.checkValue())
                setText(R.id.tv_name, it.wineryName.checkValue())
                setText(R.id.tv_price, "¥${it.consumptionPrice}/人")
                setText(R.id.tv_address, it.detailAddress.checkValue())
                setText(R.id.tv_distance, CommonUtil.formatDistance(item.distance))
                setBackgroundRes(R.id.rl_root, if (adapterPosition == pos) R.drawable.bg_stroke_e9e9e9_r6 else R.drawable.bg_solid_white_r6)
                //标签
                if (item.wineryLabelConfigFeature.checkNotNull()) {
                    setGone(R.id.fl_label, true)
                    val flLabel = getView<TagCloudView>(R.id.fl_label)
                    val tagList = mutableListOf<LabelConfigFacilityBean>()
                    tagList.addAll(item.wineryLabelConfigFeature)
                    flLabel.removeAllViews()
                    val labels = mutableListOf<String>()
                    tagList.forEach {
                        labels.add(it.labelName)
                    }
                    flLabel.setTags(labels)
                } else {
                    setGone(R.id.fl_label, false)
                }
            }
        }
    }

    var pos = 0

    //选中 标记
    fun setSelectTag(pos: Int) {
        this.pos = pos;
        notifyDataSetChanged()
    }

}